// 这是我的第一行js代码
console.log('Hello World')
// let和const的区别是let可以直接改变其值，而const不能；而且const在声明时必须给其赋值
// let
let age = 30;
age = 25;
console.log('age:' + age);
// const
// const name ='IloveJs';
// name='IloveJs';
// console.log('name:'+name);

const username = 'Victor';
const myage = 21;
// 请注意，Js中不分浮点和整形，都是number类形
const rate = 2.1;
const isCool = true;
// null和undefined的区别是一个是定义为空，另一个根本没有定义
const x = null;
const y = undefined;
let z;

console.log(typeof rate)

//字符连接的两种方式
console.log("My name is " + username + "and my age is " + age);
console.log(`My name is ${username} and my age is ${age}`);
const victor = `My name is ${username} and my age is ${age}`;
console.log(victor);

// 字符串的内置方法
const s = "I love JS";
console.log(s.length);
console.log(s.toUpperCase());
console.log(s.toLowerCase());
console.log(s.substring(0, 6).toUpperCase());
console.log(s.split(""));
const stl = "technology,computer,it,code";
console.log(stl.split(","))

// 数组
const numbers = new Array(1, 2, 3, 4, 5);
console.log(numbers);

const fruits = ["Apple", "Orange", "Pear"];
fruits[3] = "Grape";
fruits.push("mangos");
fruits.unshift("strawbarryes");                      
fruits.pop();
console.log(fruits[1]);
console.log(fruits);
console.log(Array.isArray(fruits));
console.log(Array.isArray(123));
console.log(fruits.indexOf("Orange"));

// 对象
const person = {
    firstName: "Victor",
    lastName: "Kite",
    age: 21,
    hobbies: ["music", "movies", "sports"],
    address: {
        street: "86 Wenjiao st",
        city: "Ningbo",
        provence: "ZHEJIA"
    }
};
console.log(person);
console.log(person.firstName, person.hobbies[1], person.address.street);
// 抽取结构中的对象
const {
    firstName, 
    lastName,
    address: { city }
} = person;
console.log(city);

person.email='wuyq030410@gmail.com';
console.log(person);

// 对象数组
const todoList=[
    {
        id:1,
        text:"Learn JS",
        isCompleted:false
    },
    {
        id:2,
        text:"Learn HTML",
        isCompleted:false
    },
    {
        id:3,
        text:"Learn CSS",
        isCompleted:false
    }
];
console.log(todoList);
console.log(todoList[1].text);
const todoListJson=JSON.stringify(todoList);
console.log(todoListJson);

// 条件语句
// ===和==的区别在于前者在判断时会考虑声明的变量类型
const a=10;
const b=4;
if(a === 10){
    console.log("x=10");
} else if (x > 10) {
    console.log("x>10");
}else if(x<10){
    console.log(x<10);
}

// 三目运算符
const c=10;
const color = x > 10 ? 'red' : 'blue';
console.log(color);

// switch
const d=11;
switch (color) {
    case 'red':
        console.log('The color is red');
        break;
    case 'blue':
        console.log('The color is blue');
    default:
        console.log('The color is Not red or blue');
        break;
}

// for循环
for(let i=0;i<=4;i++){
    console.log(`For Loop Number:${i}`);
}
for(let todo of todoList){
    console.log(todo.text)
}
// while循环
let i=0;
while(i<=4){
    console.log(`While Loop Number:${i}`);
    i++;
}